package com.jgp.workflow.controller;

import com.jgp.security.config.SecUserAdapter;
import com.jgp.security.pojo.UserInfo;
import com.jgp.sys.controller.JGPController;
import com.jgp.sys.service.ConfigService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 项目   jgp-cloud-parent
 * 作者   loufei
 * 时间   2019/1/7
 */
public class JGPProcController extends JGPController {
    
    @Autowired
    private ConfigService configService;
    
    @Autowired
    private SecUserAdapter userAdapter;
    
    @ModelAttribute
    public void common(HttpServletRequest request,Model model) {
        UserInfo user = userAdapter.currentUser();
        String businessKey = request.getParameter("businessKey");
        String procId = request.getParameter("procId");
        String taskId = request.getParameter("taskId");
        String editFlag = request.getParameter("editFlag");
        String userId = user.getId();
        String claimState = request.getParameter("claimState");
        Map<String, Object> onceConfig = configService.getOnceConfig();
        if(StringUtils.isNotBlank(claimState)&&claimState.equals("other")){
            editFlag = "false";
        }
        model.addAttribute("businessKey",businessKey);
        model.addAttribute("procId",procId);
        model.addAttribute("taskId",taskId);
        model.addAttribute("editFlag",Boolean.valueOf(editFlag));
        model.addAttribute("userId",userId);
        model.addAttribute("claimState",claimState);
        onceConfig.put("workflow", new Props(businessKey, procId, taskId, editFlag, userId, claimState));
    }
    
    
    class Props {
        private String businessKey;
        private String procId;
        private String taskId;
        private String editFlag;
        private String userId;
        private String claimState;
        
        public Props(String businessKey, String procId, String taskId, String editFlag, String userId, String claimState) {
            this.businessKey = businessKey;
            this.procId = procId;
            this.taskId = taskId;
            this.editFlag = editFlag;
            this.userId = userId;
            this.claimState = claimState;
        }
        
        public String getBusinessKey() {
            return businessKey;
        }
        
        public void setBusinessKey(String businessKey) {
            this.businessKey = businessKey;
        }
        
        public String getProcId() {
            return procId;
        }
        
        public void setProcId(String procId) {
            this.procId = procId;
        }
        
        public String getTaskId() {
            return taskId;
        }
        
        public void setTaskId(String taskId) {
            this.taskId = taskId;
        }
        
        public String getEditFlag() {
            return editFlag;
        }
        
        public void setEditFlag(String editFlag) {
            this.editFlag = editFlag;
        }
        
        public String getUserId() {
            return userId;
        }
        
        public void setUserId(String userId) {
            this.userId = userId;
        }
        
        public String getClaimState() {
            return claimState;
        }
        
        public void setClaimState(String claimState) {
            this.claimState = claimState;
        }
    }
}
